const Spa = {
                //使用路径前使用 #!
                create: function (pageContainerId, menuSelector, rootPath) {
                    let _spa = {};
                    let $bodypage = $(pageContainerId);
                     
                    _spa.loadAjaxPage = function loadAjaxPage(url) {
                        $.get(url, null, function (rsp) {  
                            $bodypage.html(rsp);     
                        });
                    }

                    _spa.init = function () {
                        window.onpopstate = function (event) {
                            //alert(123);
                            //if (event.state == null)
                            //    return;
                            //_spa.loadAjaxPage(event.state.url);
                        }

                        window.onhashchange = function (event) {
                            let url = window.location.href; 
                            let index = url.indexOf("#!"); 
                            if (url.indexOf("#!") < 0) {
                                _spa.loadAjaxPage("#!index");
                            } else {
                                _spa.loadAjaxPage(url.substr(index + 2)); 
                            } 
                        }

                        $(menuSelector).click(function (e) {   
                            let url = $(e.target).attr("href"); 
                            let state = { url: url };
                            history.pushState(state, "title", url);
                            url = url.replace("#!", rootPath);
                            _spa.loadAjaxPage(url);
                            e.preventDefault();
                            return false;
                        });

                        let url = window.location.href;
                        if (url.indexOf("#!") > 0) {
                            url = url.substr(url.indexOf("#!") + 2); 
                            _spa.loadAjaxPage(url);

                        }
                    };

                    return _spa;
                }
            };